package nextoffer;

import java.util.Arrays;
import java.util.Scanner;

public class Tencent {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i= 0 ; i < n;i++){
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int niuzhanli = 0;
        int tisheng = 0;
        for(int i = 0,j = n - 1 ; i <= j;i++ , j--){
            if(i==j){
                if(niuzhanli < arr[j]) {
                    tisheng += arr[j] - niuzhanli;
                    niuzhanli = arr[j];
                } else {
                    niuzhanli = arr[i];
                }
                break;
            }
            if(niuzhanli < arr[j]) {
                tisheng += arr[j] - niuzhanli;
                niuzhanli = arr[j];

            }
            if(niuzhanli >= arr[i]){
                niuzhanli = arr[i];
            }

        }
        System.out.println(tisheng);
    }

}
